package org.example.aaaatest.xml;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.io.StringWriter;

/**
 * @description:
 * @author: wangbaogui
 * @create: 2025/3/7 18:30
 **/
public class jsonXml {
    public static void main(String[] args) throws JAXBException {
        // 创建 Route 对象并填充数据
        Route route = new Route();
        route.setSdkVer("3.8.1.0");
        route.setType("0x0d");
        route.setFlag("0x00861078");
        route.setSource("amap");
        route.setVers("5.1");
        route.setUuid("93264245839429632");
        route.setContentOptions("0x73ec340be");
        route.setDisFlag("0x1");

        // 填充子对象
        Route.Location location = new Route.Location();
        location.setType("0x0A");
        route.setLocation(location);

        Route.Destination destination = new Route.Destination();
        destination.setType("2");
        destination.setTypecode("500100");
        destination.setNaviExtCode("2");
        route.setDestination(destination);

        Route.StartPoint startpoint = new Route.StartPoint();
        startpoint.setType("1");
        startpoint.setStartX(118.839084);
        startpoint.setStartY(31.911465);
        route.setStartpoint(startpoint);

        Route.EndPoint endpoint = new Route.EndPoint();
        endpoint.setType("1");
        endpoint.setEndX(118.810758);
        endpoint.setEndY(31.913138);
        route.setEndpoint(endpoint);

        Route.Avoid avoid = new Route.Avoid();
        avoid.setType("0");
        route.setAvoid(avoid);

        // 转换为 XML
        JAXBContext jaxbContext1 = JAXBContext.newInstance(Route.class);
        Marshaller marshaller = jaxbContext1.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // 格式化输出
        StringWriter writer = new StringWriter();
        marshaller.marshal(route, writer);
        String xml1 = writer.toString();
        System.out.println(xml1);

    }
}
